package com.mvu.banana.common;

import com.mvu.banana.gwttest.MyGWTTestSuite;
import junit.framework.Test;
import junit.framework.TestSuite;

import java.io.File;
import java.io.FilenameFilter;
import java.util.Enumeration;

/**
 */
public class SuiteUtil {
  private final static FilenameFilter filter = new FilenameFilter() {
    @Override
    public boolean accept(File dir, String name) {
      return name.endsWith("Test.java");
    }
  };
  public static void addPackage(TestSuite suite, Package pack) throws Exception {
    String packageName = pack.getName();
    File folder = new File("src/test/java/", packageName.replace('.', '/'));
    for(String name : folder.list(filter)){
      Class testClass = Class.forName(packageName + "." + name.substring(0, name.length()-5));
      suite.addTestSuite(testClass);
    }
  }

  public static void addSuite(TestSuite suite, TestSuite suiteToAdd) {
    Enumeration<Test> iterator = suiteToAdd.tests();
    while(iterator.hasMoreElements()){
      suite.addTest(iterator.nextElement());
    }
  }
}
